package xyz.haijin.shiro.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import xyz.haijin.shiro.entity.Menu;
import xyz.haijin.shiro.entity.User;
import xyz.haijin.shiro.service.MenuService;
import xyz.haijin.shiro.util.Constants;

import javax.security.auth.Subject;
import java.util.List;

@Controller
public class PageController {
    @Autowired
    private MenuService menuService;

    @RequestMapping("index.html")
    public String index() {
        return "index";
    }

    @RequestMapping("side.html")
    @ResponseBody
    public List<Menu> sideMenu() {
        Session session = SecurityUtils.getSubject().getSession();
        User user = (User) session.getAttribute(Constants.SESSION_USER);
        return menuService.getUserMenu(user.getId());
    }
//    @Autowired
//    private MyShiroFilterFactoryBean shiroFilterFactoryBean;
//
//    @RequestMapping("update.html")
//    public String update() {
//        shiroFilterFactoryBean.update();
//        return "index";
//    }

    @RequestMapping("error.html")
    public String error() {
        return "error";
    }

//    @RequestMapping("do{path}.html")
//    public String page(@PathVariable(name = "path") String path, Model model) {
//        model.addAttribute("path", path);
//        return "test";
//    }
}
